from manimlib import *

LV,QL,QH,JH='#75cfb8','#bbdfc8','#f0e5d8','#ffc478'

class p1(Scene):
    def construct(self):
        # self.add(NumberPlane())
        width=6
        height=6
        b,c,d,a=[-width/2,height/2,0],[width/2,height/2,0],[width/2,-height/2,0],[-width/2,-height/2,0]
        e,f=[1.89,-1.16,0],[1.39,-3,0]
        r=6/(1+np.sqrt(2))
        p=a+np.array([r,r,0])
        # geo
        circle=Circle(r).move_to(p)
        arc=Arc(width,0,PI/2,arc_center=a)
        tangent=Line(c,f)
        self.add(Square(width),circle,arc,tangent)
        self.add(
            Tex('A').next_to(a,DL),
            Tex('B').next_to(b,UL),
            Tex('C').next_to(c,UR),
            Tex('D').next_to(d,DR),
            Tex('E').next_to(e),
            Dot(p,0.05),
            Tex('P').next_to(p),
            Arc(1,255*DEGREES,15*DEGREES,arc_center=c)
        )
        self.wait()
class p2(Scene):
    def construct(self):
        # self.add(NumberPlane())
        width=6
        height=6
        b,c,d,a=[-width/2,height/2,0],[width/2,height/2,0],[width/2,-height/2,0],[-width/2,-height/2,0]
        e,f=[1.89,-1.16,0],[1.39,-3,0]
        r=6/(1+np.sqrt(2))
        p=a+np.array([r,r,0])
        # geo
        circle=Circle(r).move_to(p)
        q=circle.get_bottom()
        arc=Arc(width,0,PI/2,arc_center=a)
        tangent=Line(c,f)
        self.add(Square(width),circle,arc,tangent)
        self.add(
            Tex('A').next_to(a,DL),
            Tex('B').next_to(b,UL),
            Tex('C').next_to(c,UR),
            Tex('D').next_to(d,DR),
            Tex('E').next_to(e),
            Tex('P').next_to(p,UP),
            Arc(1,255*DEGREES,15*DEGREES,arc_center=c),
            Line(a,c),
            Line(p,circle.get_left())
        )
        # p2
        pq=Line(p,q)
        pe=Line(e,p)
        ce=Line(e,c)
        q=p+DOWN*r
        self.add(pq,pe)
        self.add(
            Tex('Q').next_to(q,DOWN),
            Tex('r').shift(RIGHT*0.5),
            Angle(ce,pe,elbow=True,color=BLACK)
        )
        self.wait()